"""
写添加日程页面的信息
"""
from selenium.webdriver.common.by import By
from pages.base_page import BasePage
from selenium.webdriver.support.select import Select
class RctjPage(BasePage):
    url = ("http://192.168.1.55/crm/index.php?m=event&a=add")
    zt_locator = (By.ID, "subject")

    start_data_locator = (By.ID, "start_date")
    end_date_locator = (By.ID, "end_date")
    where_locator = (By.ID, "venue")
    email_locator = (By.CSS_SELECTOR, '[value="0"]')

    xzxg_loctor = (By.ID, 'select1')
    xzxg_xs_locator = (By.ID, 'module_name')
    # 清楚数据定位表格
    tbody_locator = (By.XPATH, '//*[@id="data"]')
    xzxg_khsure_locator = (By.XPATH, "/html/body/div[9]/div[3]/div/button[1]/span")

    miaoshu_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tbody/tr[6]/td[2]/textarea")
    baocun_locator = (By.XPATH, "/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]")
    def zt_input(self,zhuti):
        """主题输入框"""
        self.driver.find_element(*self.zt_locator).send_keys(zhuti)
    def start_data_input(self):
        """开始时间输入框"""
        self.driver.find_element(*self.start_data_locator).send_keys("2018-02-12")
    def end_data_input(self):
        """结束时间输入框"""
        self.driver.find_element(*self.end_date_locator).send_keys("2018-03-12")
    def where_input(self,place):
        """地点输入框"""
        self.driver.find_element(*self.where_locator).send_keys(place)

    def xzxg_click(self,name):
        """点击日程相关"""
        xzxg_locator = self.driver.find_element(*self.xzxg_loctor)
        select = Select(xzxg_locator)
        select.select_by_index(2)  # 选择相关为线索
        self.driver.find_element(*self.xzxg_xs_locator).click()

        tbody = self.driver.find_element(*self.tbody_locator)
        trs = tbody.find_elements(By.TAG_NAME, "tr")
        for i in trs:
            tds = i.find_elements(By.TAG_NAME, 'td')
            if tds[1].text == name:
                tds[0].find_element(By.CSS_SELECTOR, 'input[name="leads"]').click()
                break
        self.driver.find_element(*self.xzxg_khsure_locator).click()

    def email_click(self):
        """点击邮件发送"""
        self.driver.find_element(*self.email_locator).click()

    def miaosu_input(self,content):
        """描述输入框"""
        self.driver.find_element(*self.miaoshu_locator).send_keys(content)
    def baocun_click(self):
        """点击保存"""
        self.driver.find_element(*self.baocun_locator).click()

    def open(self):
        """打开页面地址"""
        self.driver.get(self.url)